<?php
// $Id: ProfileController.php 643 2013-01-20 07:37:45Z tomqin@gmail.com $

/**
 * Part of the framework.
 *
 * @package     Controller
 * @version     1.0
 * @copyright   Copyright (C) 2010-2012 SupeFun.com Inc.
 * @author      TomQin <tomqin@gmail.com>
 * @license     http://www.supefun.com/license/
 */

class ProfileController extends MemberController
{
    public $shopInfo = array();

    public function beforeAction() {
        parent::beforeAction();

        $this->shopManager = Base::getObject('service.manager.shopManager');
        $this->shopInfo = $this->shopManager->setShopId($this->shopId)->getData();
        if(!$this->shopInfo){
            $this->renderMessage('店铺不存在或者已删除');
        }
    }

    //在中间加了一层
    public function indexAction() {
        $this->setVar('data', $this->shopInfo);
        $this->render('m_profile');
    }

    public function saveAction() {
        if(!get_request('submitform')){
            header('Location: /account.php?m=biz&c=profile');
        }

        $error = $this->check();

        if(!$error){
            $this->shopManager
                 ->setField('name', get_request('name'))
                 ->setField('contact', get_request('contact'))
                 ->setField('mobile', get_request('mobile'))
                 ->setField('address', get_request('address'))
                 ->setField('picture', get_request('picture'))
                 ->setField('longitude', get_request('longitude'))
                 ->setField('latitude', get_request('latitude'))
                 ->setField('city_id', intval(get_request('city_id')))
                 ->setField('area_id', intval(get_request('area_id')))
                 ->setField('update_dt', TIMESTAMP)
                 ->updateDb();
            $this->renderMessage('商户信息编辑成功');
        }else{
            $this->setVar('error', $error);
            $this->setVar('data', get_request());
            $this->render('m_profile');
        }
    }

    public function check() {

        $error = array();
 /*
        //送餐电话
        $telphones = get_request('telphone');
        $telnum = 0;;
        foreach($telphones as $tel){
            if($tel){
                if(Validate::isTelphone($tel)) {
                    $telnum ++;
                }else{
                    $error['telphone'] = '送餐电话号码格式错误';
                }
            }
        }
        if(!$telnum){
            $error['telphone'] or $error['telphone'] = '至少添加一部送餐电话';
        }

        //配送说明
        $desc = get_request('delivery_desc');
        if(iconv_strlen($desc) < 10 || iconv_strlen($desc) > 250){
            $error['delivery_desc'] = '配送说明保证在10～250个字符之间'.iconv_strlen($desc);
        }*/
        return $error;
    }
}
